/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bank.core;

import bank.notifications.OrganizationNotification;
import bank.notifications.PersonalNotification;
import frmwrk.core.Account;
import frmwrk.core.AccountFactory;
import frmwrk.core.Organization;
import frmwrk.interfaces.IParty;
import java.util.HashMap;
import java.util.List;
import java.util.Observer;

/**
 *
 * @author akefeli
 */
public class BankAccountFactory extends AccountFactory{
 
    public Account create(HashMap<String, String> params,IParty party, List<Observer> observers ) {

        Account ret = null;
        int accountNumber = Integer.parseInt(params.get("accountNumber"));
        Double balance = Double.valueOf(params.get("balance"));

        if (params.get("accountType").equals("Saving")) {

            ret = new SavingAccount(accountNumber, balance);

        } else if (params.get("accountType").equals("Checking")) {

            ret = new CheckingAccount(accountNumber, balance);

        } else {
            System.out.println("Wrong type for account");
            return null;
        }
        
        ret.setParty(party);
        
        for(Observer observer : observers)
            ret.addObserver(observer);
        
        if (params.get("partyType").equals("Person")) {
            ret.addObserver(PersonalNotification.getInstance());
        } else if (params.get("partyType").equals("Organization")) {
            ret.addObserver(OrganizationNotification.getInstance());
        }
        
        return ret;
    }
}
